<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
    <link rel="stylesheet" href="/style/login.css" media="all">
</head>
<body style="overflow: hidden;">
<div class="layui-fluid">
    <div class="layui-row  layui-col-space10">
        <div class="layui-col-xs12">
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                           for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="username" value="" lay-verify="required"
                           placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="password" value="" lay-verify="required"
                           placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item input-item" id="imgCode">
                    <table>
                        <tr>
                            <td style="width: 58%">
                                <input type="text" placeholder="请输入验证码" autocomplete="off" id="randomcode" name="randomcode"
                                       class="layui-input"
                                       lay-verify="required">
                            </td>
                            <td style="width: 2%" ></td>
                            <td style="width: 40%">
                                <img src="/validateCodeServlet" class="layadmin-user-login-codeimg" id="vercode_img" style="height: 100%;">
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="layui-form-item" style="margin-bottom: 20px;">
                <#--<input type="checkbox" name="rememberMe" id="rememberMe" lay-skin="primary" title="记住我">-->
                <#--<a href="forget.html" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>-->
                </div>
                <div class="layui-form-item">
                    <button id="submitBtn" class="layui-btn layui-btn-fluid" lay-submit
                            lay-filter="LAY-user-login-submit">登 入
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/plugins/jquery/jquery.min.js" charset="utf-8"></script>
<script src="/plugins/jquery/jquery.base64.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var $ = layui.$
                , form = layui.form;
        form.render();
        var parentIndex = parent.layer.getFrameIndex(window.name);
        form.on("submit(LAY-user-login-submit)", function (obj) {
            var username = $.base64.encode($("#username").val());
            var password = $.base64.encode($("#password").val());
            var randomcode = $.base64.encode($("#randomcode").val());
//            var vcode = $("#vcode").val();
            var rememberMe = $('#rememberMe').is(':checked');
            $.post("/login/validate", {
                "username": username,
                "password": password,
                "randomcode": randomcode,
//                "vcode" : vcode,
                "rememberMe": rememberMe
            }, function (data) {
                if (data.status == '0') {
                    layer.msg("登录成功", {anim: 0, icon: 1});
                    parent.layer.close(parentIndex);
                } else {
                    layer.msg(data.message, {offset: '15px', anim: 6, icon: 2, time: 2000});
                    reloadCode();
                }
            });
        });
        function reloadCode() {
            var vercode_img = $("#vercode_img").get(0);
            vercode_img.src = "/validateCodeServlet?t=" + new Date().getTime();
        }

        $("#vercode_img").click(function () {
            reloadCode();
        });
        $("body").keydown(function () {
            if (event.keyCode == "13") {//keyCode=13是回车键
                $('#submitBtn').click();
            }
        });
    });
</script>
</body>
</html>